from gmtrade import api as xtconstant
import datetime
code2name_order_status={
xtconstant.OrderStatus_New : "已报",          # 已报
xtconstant.OrderStatus_PartiallyFilled : "部成",
xtconstant.OrderStatus_Filled : "已成",
xtconstant.OrderStatus_Canceled : "已撤",
xtconstant.OrderStatus_Rejected : "已拒绝",
xtconstant.OrderStatus_PendingNew : "待报",
xtconstant.OrderStatus_Expired : "已过期"
}
code2name_order_type={
xtconstant.OrderSide_Buy:"买入",
xtconstant.OrderSide_Sell:"卖出"
# xtconstant.CREDIT_FIN_BUY:"融资买入",
# xtconstant.CREDIT_SLO_SELL:"融券卖出",
# xtconstant.CREDIT_BUY_SECU_REPAY:"买券还券",
# xtconstant.CREDIT_DIRECT_SECU_REPAY:"直接还券",
# xtconstant.CREDIT_SELL_SECU_REPAY:"卖券还款",
# xtconstant.CREDIT_DIRECT_CASH_REPAY:"直接还款"

}
code2name_price_type={
xtconstant.OrderType_Market :"市价",
xtconstant.OrderType_Limit :"指定价"
}
order_end_stat=[3,5,8,12]
class  xtconstant00:
    def __init__(self):
        self.STOCK_BUY=xtconstant.OrderSide_Buy
        self.STOCK_SELL=xtconstant.OrderSide_Sell
        self.FIX_PRICE=xtconstant.OrderType_Limit
xtconstant0=xtconstant00()
def gmpos2pos(o):
    rst={}
    rst["account_id"]=o.account_id#:"16199767-70d8-11e9-82ad-00163e0a4100"
    rst["symbol"]=o.symbol#:"SHSE.600519"
    rst["side"]=o.side#:1
    rst["volume"]=o.volume#:800
    rst["volume_today"]=o.volume_today#:800
    rst["vwap"]=o.vwap#:1627.1224975585938
    rst["amount"]=o.amount#:1301697.998046875
    rst["price"]=o.price#:1630.010009765625
    rst["fpnl"]=o.fpnl#:2310.009765625
    rst["cost"]=o.cost#:1301697.998046875
    rst["available"]=o.available#:800
    rst["available_today"]=o.available_today#:800
    rst["last_price"]=o.last_price#:1628.0
    rst["last_volume"]=o.last_volume#:100
    rst["timekey"]=datetime.datetime.fromtimestamp(o.created_at.seconds)#:1707103697
    rst["updated_at"]=datetime.datetime.fromtimestamp(o.updated_at.seconds)#:1707116231
    return rst
def gmorder2order(o):
    rst={}
    rst["account_id"]=o.account_id#: "16199767-70d8-11e9-82ad-00163e0a4100"
    rst["account_name"]=o.account_name#: "16199767-70d8-11e9-82ad-00163e0a4100"
    rst["cl_ord_id"]=o.cl_ord_id#: "12d66946-c3f3-11ee-a442-d8c4976b2f01"
    rst["order_id"]=o.order_id#: "12a5ede2-c3f3-11ee-8d3d-00163e022aa6"
    rst["ex_ord_id"]=o.ex_ord_id#: "12a5ede2-c3f3-11ee-8d3d-00163e022aa6"
    rst["symbol"]=o.symbol#: "SHSE.510050"
    rst["side"]=o.side#: 1
    rst["position_effect"]=o.position_effect#: 1
    rst["position_side"]=o.position_side#: 1
    rst["order_type"]=o.order_type#: 1
    rst["status"]=o.status#: 3
    rst["price"]=o.price#: 2.291
    rst["order_style"]=o.order_style#: 1
    rst["volume"]=o.volume#: 100
    rst["filled_volume"]=o.filled_volume#: 100
    rst["filled_vwap"]=o.filled_vwap#: 2.2860000133514404
    rst["filled_amount"]=o.filled_amount#: 228.60000133514404
    rst["timekey"]=datetime.datetime.fromtimestamp(o.created_at.seconds)
    rst["updated_at"]=datetime.datetime.fromtimestamp(o.updated_at.seconds)
    rst["filled_commission"]=o.filled_commission#: 5.0
    return rst